package parser;

import antlr.RecognitionException;
import antlr.TokenStreamException;
import collector.Collector;
import collector.FileObj;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;


public class Main {
    private Main() {
    }

    public static void parseFile(Collector collector, FileObj f) throws FileNotFoundException, TokenStreamException,
            RecognitionException {
        try {
            Reader r = new BufferedReader(new FileReader(f.getFile()));
            // Create a scanner that reads from the input stream passed to us
            CodeReviewJavaLexer lexer = new CodeReviewJavaLexer(r);

            lexer.setTokenObjectClass("parser.CodeReviewToken");

            // Create a parser that reads from the scanner
            JavaRecognizer parser = new JavaRecognizer(lexer, f);
            parser.setASTNodeClass("parser.CodeReviewAST");

            // start parsing at the compilationUnit rule
            parser.compilationUnit();
            f.lineCount = lexer.lineCount;
            //debug only: pass
            //printDecoratedText(f);

            // do something with the tree
            //System.out.println(f);
            JavaTreeParser tparser = new JavaTreeParser(collector, f);
            tparser.compilationUnit(parser.getAST());
        }
        catch (RecognitionException e) {
            throw e;
        }
    }


}

